home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapmovesel.py < prev    next >
Text File  |  2004-01-05  |  5KB  |  142 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Implementation of the Brush Subtraction commands
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mapmovesel.py,v 1.4 2003/03/24 08:57:15 cdunde Exp $
  12.  
  13.  
  14.  
  15. Info = {
  16.    "plug-in":       "Selection Movement",
  17.    "desc":          "Various movements involving multiple selections",
  18.    "date":          "8 June 2001",
  19.    "author":        "tiglari",
  20.    "author e-mail": "tiglari@planetquake.com",
  21.    "quark":         "Version 6.3" }
  22.  
  23. import quarkx
  24. import quarkpy.mapmenus
  25. import quarkpy.mapcommands
  26. import quarkpy.maphandles
  27. import mapmadsel
  28.  
  29. from quarkpy.maputils import *
  30.  
  31.  
  32. def SwapClick(m):
  33.     editor=mapeditor()
  34.     if editor is None: return
  35.     centers = map(lambda item:quarkpy.maphandles.GetUserCenter(item), m.sel)
  36.     diff = centers[1]-centers[0]
  37.     newitems = map(lambda item:item.copy(),m.sel)
  38.     newitems[0].translate(diff)
  39.     newitems[1].translate(-diff)
  40.     undo=quarkx.action()
  41.     for i in 0, 1:
  42.         undo.exchange(m.sel[i], newitems[i])
  43.     editor.ok(undo,"swap selection")
  44.  
  45.  
  46. def AlignClick(m):
  47.     editor=mapeditor()
  48.     if editor is None: return
  49.     sel=editor.layout.explorer.sellist
  50.     marked = mapmadsel.getstashed(editor)
  51.     if marked is None:
  52.        box = quarkx.boundingboxof(sel)
  53.     else:
  54.        box = quarkx.boundingboxof([marked])
  55.     def shift(item,box=box,mode=m.mode):
  56.         ibox=quarkx.boundingboxof([item])
  57.         if mode in ["up","east","north"]:
  58.             i =1
  59.         else:
  60.             i= 0
  61.         if mode in ["east","west"]:
  62.             shift=quarkx.vect(box[i].x-ibox[i].x,0,0)
  63.         elif mode in ["north","south"]:
  64.             shift=quarkx.vect(0,box[i].y-ibox[i].y,0)
  65.         else:
  66.             shift=quarkx.vect(0,0,box[i].z-ibox[i].z)
  67.         return shift
  68.     undo=quarkx.action()
  69.     for item in sel:
  70.         item2 = item.copy()
  71.         item2.translate(shift(item))
  72.         undo.exchange(item,item2)
  73.     editor.ok(undo,"align "+m.mode)
  74.  
  75.     
  76. def makeitem(mode):
  77.     item=qmenu.item("Align "+mode,AlignClick)
  78.     item.mode=mode
  79.     return item
  80.  
  81. alignlist = map(makeitem,["east","west","north","south","up","down"])
  82.  
  83. menswap = qmenu.item("Swap Selection",SwapClick)
  84. menalign = qmenu.popup("Align Group",alignlist)
  85.  
  86. def commandsclick(menu, oldcommand=quarkpy.mapcommands.onclick):
  87.     oldcommand(menu)
  88.     editor=mapeditor()
  89.     if editor is None : return
  90.     sel = editor.layout.explorer.sellist
  91.     menhint = "|Swap Selection:\n\nSwap first and second elements of 2 selected items."
  92.     menswap.state=qmenu.disabled
  93.     if len(sel)<2:
  94.         menhint=menhint+"\n\nThis menu item requires that two items be selected; you don't have enough.|intro.mapeditor.menu.html#makeprism"
  95.     elif len(sel)>2:
  96.         menhint=menhint+"\n\nThis menu item requires that two items be selected, you have too many.|intro.mapeditor.menu.html#makeprism"
  97.     menswap.hint = menhint
  98.     if len(sel)==2:
  99.         menswap.state=qmenu.normal
  100.     menswap.state=qmenu.normal
  101.  
  102.     alignhint = "|Align selected:\n\nAlign items in selection along their bounding box edges, or along the edges of a marked object (RMB I Navigate Tree I <item> \ Mark)."
  103.     menalign.state=qmenu.normal
  104.     marked=mapmadsel.getstashed(editor)
  105.     if marked is None:
  106.         menalign.text = "Align selected (to bbox edge)"
  107.     else:
  108.         menalign.text = "Align selected (to marked)"
  109.     if len(sel)<2:
  110.         if marked is None:
  111.             alignhint=alignhint+"\n\nThis menu item requires that two or more items be selected, or that something be marked; neither of these are true.|intro.mapeditor.menu.html#makeprism"
  112.             menalign.state=qmenu.disabled
  113.         elif len(sel)<1:
  114.             alignhhint=alignhint+"\n\nNothing to align.|intro.mapeditor.menu.html#makeprism"
  115.             menaligned.state=qmenu.disabled
  116.         elif sel[0] is marked:
  117.             alignhint=alignhint+"\n\nNo point in aligning something to itself (the selected item is also the marked one).|intro.mapeditor.menu.html#makeprism"
  118.             menalign.state=qmenu.disabled
  119.     menalign.hint=alignhint
  120.  
  121. quarkpy.mapcommands.onclick = commandsclick
  122.  
  123. # ----------- REVISION HISTORY ------------
  124. #
  125. quarkpy.mapcommands.items.append(menswap)
  126. quarkpy.mapcommands.items.append(menalign)
  127.  
  128. # $Log: mapmovesel.py,v $
  129. # Revision 1.4  2003/03/24 08:57:15  cdunde
  130. # To update info and link to infobase
  131. #
  132. # Revision 1.3  2001/07/24 01:10:39  tiglari
  133. # menu item text now says whether to marked or not
  134. #
  135. # Revision 1.2  2001/07/23 23:41:13  tiglari
  136. # Now aligns to marked, if anything is marked
  137. #
  138. # Revision 1.1  2001/06/07 21:30:15  tiglari
  139. # swap & align (suggestions by Alan Donald (swap) & quantum_red (align)
  140. #
  141. #
  142.